package org.hagopa.games.moneypool.game;

import java.sql.Date;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

import org.hagopa.games.moneypool.dblayer.DBStructure;
import org.hagopa.games.moneypool.dblayer.Connector.DBConnector;

public class GameData implements DBStructure{
	private DBConnector localRefDBConn = null;
	private int MaxPlayers = 0;
	private long gameId = 0;
	private Date startDate = null;
	private int boardId = 0;
	private List<Long> playersIdList = new ArrayList<Long>();
	private int total_players = 0;
	private String sqlrequest = null;
	private Bank gbank = null;
	
	public GameData(long gameId)
	{
		this.gameId = gameId;
		sqlrequest = "SELECT * FROM games WHERE id=" + this.gameId; 
	}
	
	public boolean loadData() {
		System.out.println("Loading Game Data...");
		Statement stmt = null;
		ResultSet rs = null;
		try {
			stmt = DBConnector.getConn().createStatement();
						
			rs = stmt.executeQuery(sqlrequest);
		
			while(rs.next())
			{
				//Retrieve by column name
				this.gameId = rs.getInt("id");
				this.startDate = rs.getDate("start_date");
				int startSum = 0;
				int startPay = 0;
				gbank = new Bank(startSum, startPay);	
				playersIdList.add(1,new Long(10));
			}

			rs.close();
			stmt.close();
		
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return false;
		}
		return true;
	}
	public DBConnector getLocalRefDBConn() {
		return localRefDBConn;
	}
	public void setLocalRefDBConn(DBConnector localRefDBConn) {
		this.localRefDBConn = localRefDBConn;
	}

	public int getBoardId() {
		return boardId;
	}

	public long getGameId() {
		return gameId;
	}

	public int getMaxPlayers() {
		return MaxPlayers;
	}

	public Date getStartDate() {
		return startDate;
	}

	public int getTotal_players() {
		return total_players;
	}
	
	
	public boolean storeStatus2DB(){
		//dummy, for futher usage (statistics, and so on)
		return true;
	}
}
